package cn.liccshop.core.service.shopGoodsAttr.controller;


import cn.liccshop.core.entity.ShopGoodsAttr;
import cn.liccshop.core.service.shopGoodsAttr.service.IShopGoodsAttrService;
import cn.liccshop.core.utils.ObjectToOtherUtils;
import cn.liccshop.sys.constants.Constants;
import cn.liccshop.sys.entity.Result;
import cn.liccshop.sys.exception.MySystemException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.liccshop.sys.base.MyActionController;

import java.util.List;
import java.util.Map;

/**
 * @description 商品属性表 前端控制器
 *
 * @author LiCC
 * @since 2019-04-08
 */
@RestController
@RequestMapping("/shopGoodsAttr")
public class ShopGoodsAttrController extends MyActionController<ShopGoodsAttr> {

    @Autowired
    private IShopGoodsAttrService liShopGoodsAttrService;

    @Override
    protected IService<ShopGoodsAttr> getLiService(){
        return liShopGoodsAttrService;
    }

    @RequestMapping(value = "attrInfoByGoodsId")
    public Result getShopGoodsAttrByGoodsId(@RequestBody Map<String, Object> map) throws MySystemException {
        List<Map<String, List<ShopGoodsAttr>>> data = liShopGoodsAttrService.getShopGoodsAttrByGoodsId(ObjectToOtherUtils.toString(map.get("goodsId")),ObjectToOtherUtils.toString(map.get("catId")));
        return new Result().setCode(Constants.OK).setData(data).setMessage("获取信息成功");
    }

    /**
     * 添加库存时初始化
     * @param map
     * @return
     * @throws MySystemException
     */
    @RequestMapping(value = "initProducts")
    public Result shopGoodsAttrByGoodsIdAndCatId(@RequestBody Map<String, Object> map) throws MySystemException {
        Map<String, Object> data = liShopGoodsAttrService.shopGoodsAttrByGoodsIdAndCatId(ObjectToOtherUtils.toString(map.get("goodsId")),ObjectToOtherUtils.toString(map.get("catId")));
        return new Result().setCode(Constants.OK).setData(data).setMessage("获取信息成功");
    }
    /**
     * 编辑商品库存初始化
     * @param map
     * @return
     * @throws MySystemException
     */
    @RequestMapping(value = "initProductsInfo")
    public Result shopProductsByGoodsIdAndCatId(@RequestBody Map<String, Object> map) throws MySystemException {
        Map<String, Object> data = liShopGoodsAttrService.shopProductsByGoodsIdAndCatId(ObjectToOtherUtils.toString(map.get("goodsId")),ObjectToOtherUtils.toString(map.get("catId")));
        return new Result().setCode(Constants.OK).setData(data).setMessage("获取信息成功");
    }
}

